package jupitermouse.site.example.scala.window

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.windowing.time.Time

object StreamTimeApp {

  def main(args: Array[String]): Unit = {

    val env = StreamExecutionEnvironment.getExecutionEnvironment

    val streamSet = env.socketTextStream("localhost",9999)

    import org.apache.flink.api.scala._

//    timeWindow/countWindow 默认是处理时间
/*
    streamSet.flatMap(_.split(" "))
      .map((_,1))
      .keyBy(0)
      .timeWindow(Time.seconds(5))//.window(TumblingProcessingTimeWindows.of(size))
      .sum(1)
      .print()
      .setParallelism(1)
*/

    streamSet.flatMap(_.split(" "))
      .map((_,1))
      .keyBy(0)
      //会有重叠
      .timeWindow(Time.seconds(10), Time.seconds(5))//SlidingProcessingTimeWindows.of(size))
      .sum(1)
      .print()
      .setParallelism(1)

    env.execute("WindowsAPP")

  }


}
